package Text_15;

public class Regexdemo {

	public static void main(String[] args) {
		//用正则表达式验证用户名是否正确
		//大小写字母，数字，下划线共4-16位
		String regex1 = "\\w{4,16}";
		System.out.println("zhangsan".matches(regex1));
		//用正则表达式验证身份证号码是否正确
		//18位，前17位任意数字，最后一为可以是数字也可以是大小写字母x
		String regex2 = "[1-9]\\d{16}(X|x|\\d)";
		//[Xx\\d];任选其中之一
		String regex3 = "[1-9]\\d{16}(X|x|\\d)";
		//(?i)x 忽略大小写
		String regex4 = "[1-9]\\d{16}(\\d|(?i)x)";
		System.out.println("65282820040813125x".matches(regex2));
		System.out.println("65282820040813125x".matches(regex3));
		System.out.println("65282820040813125X".matches(regex4));
		////用正则表达式验证邮箱是否正确
		String regex5 = "\\w+@[\\w&&[^_]]{2,6}(\\.[a-zA-Z]{2,3}){1,2}";
		System.out.println("bozai@itcast.cn".matches(regex5));
	}

}
